#include "media_controller.h"
#include "gui.h"
#include "application.h"

Application * application_new(int argc, char **argv, CPC800 *telescope, MediaController *media_controller, GUI *gui) {
	Application *app = (Application *) malloc(sizeof(Application));
	app->argc = argc;
	app->argv = argv;
	app->telescope = telescope;
	app->media_controller = media_controller;
	app->gui = gui;
	return app;
}

void application_free(Application *application) {
}

void application_execute(Application *application) {
	media_controller_init(application);
	gui_init(application);
}

void application_turn_off(Application *application) {
	gui_toggle_sensitive_widgets(application->gui, FALSE);
	gui_set_coordinate_labels_default_text(application->gui, NO_VALUE);
	serial_device_close(application->telescope->sdd);
}

void application_turn_on(Application *application) {
	char *path = (char *) gtk_entry_get_text(GTK_ENTRY(application->gui->entry_telescope));
	application->telescope->sdd = serial_device_open(path);
	if(application->telescope->sdd != ERROR) {
		gui_toggle_sensitive_widgets(application->gui, TRUE);
		gui_set_coordinate_labels_default_text(application->gui, NO_VALUE);
	}
	else gtk_switch_set_active(GTK_SWITCH(application->gui->switch_on), FALSE);
}
